import { Injectable } from '@nestjs/common';
import { InjectRepository } from '@nestjs/typeorm';
import { Repository, In } from 'typeorm';
import { ResultData } from 'src/common/utils/result';
import { SysConfigEntity } from 'src/module/system/config/entities/config.entity';
import { SysNoticeEntity } from 'src/module/system/notice/entities/notice.entity';
import { ListNoticeDto } from 'src/module/system/notice/dto';

@Injectable()
export class NoticeService {
  constructor(
    @InjectRepository(SysNoticeEntity)
    private readonly sysNoticeEntityRep: Repository<SysNoticeEntity>,
  ) {
    console.log('NoticeService init');
  }
  async findAll(query: ListNoticeDto) {
    const entity = this.sysNoticeEntityRep.createQueryBuilder('entity');
    entity.where('entity.delFlag = :delFlag', { delFlag: '0' });

    if (query.noticeType) {
      entity.andWhere('entity.noticeType = :noticeType', { noticeType: query.noticeType });
    }

    if (query.platformType) {
      entity.andWhere('entity.platformType = :platformType', { platformType: query.platformType });
    }
    const list = await entity.getMany();
    return ResultData.ok(list);
  }
}
